# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Contributor: Ariadne Conill <ariadne@dereferenced.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=tzdata
pkgver=2024b
_ptzver=0.5
pkgrel=1
pkgdesc="Timezone data"
url="https://www.iana.org/time-zones"
arch="all"
license="Public-Domain"
subpackages="$pkgname-right $pkgname-doc $pkgname-utils"
source="https://www.iana.org/time-zones/repository/releases/tzcode$pkgver.tar.gz
	https://www.iana.org/time-zones/repository/releases/tzdata$pkgver.tar.gz
	https://dev.alpinelinux.org/archive/posixtz/posixtz-$_ptzver.tar.xz

	0001-posixtz-ensure-the-file-offset-we-pass-to-lseek-is-o.patch
	0002-fix-implicit-declaration-warnings-by-including-strin.patch
	"

builddir="$srcdir"
_timezones="africa antarctica asia australasia europe northamerica \
	southamerica etcetera backward factory"
options="!check" # Testsuite require nsgmls (SP)

build() {
	make cc="${CC:-gcc}" CFLAGS="$CFLAGS -DHAVE_STDINT_H=1" \
		TZDIR="/usr/share/zoneinfo"

	make -C "$builddir"/posixtz-$_ptzver posixtz
}

utils() {
	amove usr/bin
	amove usr/sbin
}

package() {
	./zic -b fat -y ./yearistype -d "$pkgdir"/usr/share/zoneinfo $_timezones
	./zic -b fat -y ./yearistype -d "$pkgdir"/usr/share/zoneinfo/right -L leapseconds $_timezones
	#./zic -b fat -y ./yearistype -d "$pkgdir"/usr/share/zoneinfo/posix $_timezones

	./zic -b fat -y ./yearistype -d "$pkgdir"/usr/share/zoneinfo -p America/New_York
	install -m444 -t "$pkgdir"/usr/share/zoneinfo iso3166.tab zone1970.tab zone.tab

	install -Dm755 -t "$pkgdir"/usr/sbin zic zdump

	install -Dm644 -t "$pkgdir"/usr/share/man/man8 zic.8 zdump.8

	rm -f "$pkgdir"/usr/share/zoneinfo/localtime
	install -Dm755 -t "$pkgdir"/usr/bin "$srcdir"/posixtz-$_ptzver/posixtz

	install -Dm644 -t "$pkgdir"/usr/share/zoneinfo "$srcdir"/leap-seconds.list
}

right() {
	pkgdesc="Timezone data for TAI-10 system clock"
	amove usr/share/zoneinfo/right
}

doc() {
	default_doc
	# The documentation is for the utils and not the main package
	install_if="docs $pkgname-utils=$pkgver-r$pkgrel"
}

sha512sums="
0e4e872d6c6d9e2ce8c4e567fcbb7658942b8544157d1e48673d9cb989f3af3379fa58e7a71ab98f4a8f2ac6727de1f8c4cd1981053409ebd8989345dc640026  tzcode2024b.tar.gz
0d86686e215672343debb3471b7e7ccb8a27f063f085c9b532d5e0470377843daa0dfb6aee0db4fb9068dd52810c69aeee914a1a7c7e603fdecda7e855020193  tzdata2024b.tar.gz
68dbaab9f4aef166ac2f2d40b49366527b840bebe17a47599fe38345835e4adb8a767910745ece9c384b57af815a871243c3e261a29f41d71f8054df3061b3fd  posixtz-0.5.tar.xz
0f2a10ee2bb4007f57b59123d1a0b8ef6accf99e568f21537f0bb19f290fff46e24050f55f12569d7787be600e1b62aa790ea85a333153f3ea081a812c81b1b5  0001-posixtz-ensure-the-file-offset-we-pass-to-lseek-is-o.patch
fb322ab7867517ba39265d56d3576cbcea107c205d524e87015c1819bbb7361f7322232ee3b86ea9b8df2886e7e06a6424e3ac83b2006be290a33856c7d40ac4  0002-fix-implicit-declaration-warnings-by-including-strin.patch
"
